package com.tentact.coolmeetingtest.util;

import jakarta.servlet.http.Cookie;

import java.util.List;

/**
 * @author 星环
 * @date 2023/2/6 9:15:11
 * @description
 */
public class OtherUtil {
    public static <T> T getFirstDefaultNull(List<T> list){
        if(list == null || list.size() == 0){
            return null;
        }
        return list.get(0);
    }

    public static Cookie getCookie(String key,String value,int maxAge){
        Cookie cookie = new Cookie(key,value);
        cookie.setMaxAge(maxAge);
        return cookie;
    }
    public static String getFromCookies(String key, Cookie[] cookies){
        if(key == null){
            return null;
        }
        for (Cookie cookie : cookies) {
            if(key.equals(cookie.getName())){
                return cookie.getValue();
            }
        }
        return null;
    }
}
